/*====================================================================================

Following scripts are used to create a  Campus Corporate Connect Web Page
Author : C3 Experts.

======================================================================================*/

$(document)
		.ready(
				function() {
					var w;
					var wh;
					var witm;
					$("html").niceScroll({
						cursorcolor : "#DC143C",
						cursorwidth : 10,
						cursorborder : "none",
						scrollspeed : 180,
						autohidemode : false,
						background : "#000000",
						cursorborderradius : "1px"
					});

					// ========================================================================================fit
					// text
					$("#container-logo h3").fitText(1.0, {
						minFontSize : 20,
						maxFontSize : '350px'
					});

					// ==============================calculate height of window
					// using setHeights() method
					setHeights();
					setBackstreatch();
					// handleMenuEvent();

					$.getJSON('data/menu_ccc.json', function(data) {
						drawMenuHeaders(data);
						calltoJMenu();
					}).fail(function(data) {
						console.log('JSON FAILURE');
					});

					// drawMenuHeaders(data)
					$.getJSON('data/ccc_title_subheader.json', function(data) {
						drawsectionHeaders(data);
					}).fail(function(data) {
						console.log('JSON FAILURE');
					});

					$.getJSON('data/about_ccc.json', function(data) {
						fillAboutPagewithData(data);
					});

					$.getJSON('data/ccc_credentials.json', function(data) {
						fillcredentials(data);
					}).fail(function(data) {
						console.log('CREDENTIAL JSON FAILURE');
					});

					$.getJSON('data/contact_content_ccc.json', function(data) {
						filldrawTableContents(data);
					});

					$.getJSON('data/ccc_offerings.json', function(data) {
						fillAndroidOfferings(data);
						fillOOPSOfferings(data);
					}).fail(function(data) {
						console.log('JSON FAILURE');
					});

					$.getJSON('data/credentialsectionmenu_ccc.json',
							function(data) {
								drawCredentialContent(data);
								// drawCredentialsLeftSectionHeaders(data);
								// drawCredentialsRightSectionHeaders(data);
							}).fail(function(data) {
						console.log('SEction JSON FAILURE');
					});

					$.getJSON('data/feedback_data.json', function(data) {
						fillFeedbackPersonal(data);
						$("#workshop_select").fancyfields();
						$('.ui-btn-inner').hide();
					}).fail(function(data) {
						console.log('JSON FAILURE FE');
					});

					$('#textarea').scroll(function() {
						$(this).css("overflow", "hidden"); /*
															 * for the mozilla
															 * browser problem
															 */
						$(this).animate({
							scrollTop : $(this).outerHeight()
						});
						while ($(this).scrollTop() > 0) { /*
															 * for the copy and
															 * paste case
															 */
							lines = $(this).val().slice(0, -1);
							$(this).val(lines);
						}
						$(this).css("overflow", "auto"); /*
															 * For the mozilla
															 * browser problem
															 */
					});

					$.getJSON('data/content_feedback_data.json',
							function(data) {
								fillFeedbackcourse(data);
								applyFancyfield(data);

							}).fail(function(data) {
						console.log('JSON FAILURE FE');
					});

					$("#span-home").click(function() {
						$(window).stop(true).scrollTo('0px', 1500, {
							easing : 'easeInOutExpo'
						});

					});

					function setBackstreatch() {
						if (setHeights()) {
							$
									.backstretch(
											[
													"http://localhost:8080/CCC/img/ccc/bg-21.jpg",
													"http://localhost:8080/CCC/img/ccc/bg-23.jpg",
													"http://localhost:8080/CCC/img/ccc/bg-26.jpg",
													"http://localhost:8080/CCC/img/ccc/bg-24.jpg", ],
											{
												fade : 500,
												duration : 500
											});

						}

					}

					// ================================================ menu
					// toggle effect
					$(".institutes-viewport, .admission-window").hover(

					function() {
						$(this).stop(true).animate({
							marginLeft : '0%'
						}, {
							duration : 600,
							easing : 'easeInOutExpo'
						});

					},

					function() {
						$(this).stop(true).animate({
							marginLeft : '-100%'
						}, {
							duration : 1000,
							easing : 'easeInOutExpo'
						});

					});

					// =========================================================================================set
					// heights here
					function setHeights() {

						w = $(window);
						wh = w.height();
						ww = parseInt(w.width());

						// $("#wrapper-lvl-1").css("height", wh);
						$(
								"#wrapper-lvl-4, #admissions-mba, #admissions-mca, #admissions-txtLarge, #wrapper-lvl-6")
								.css("height", wh);
						// $("#container-rightInfo").css("height", wh);

						wi = parseInt($("#wrapper-intro").height());

						witm = (wh - wi) - 60;

						$("#wrapper-intro").css("margin-top", witm + "px");

						return true;

					}

					// ========================================================================================on
					// resize() of window

					$(window).resize(function() {
						setHeights();
						setBackstreatch();
					});

					$("#ticker03").liScroll({
						travelocity : 0.03
					});

					// calltoJMenu();
				});// =================================document.ready() ends

function fillFeedbackPersonal(personaldata) {
	var feedbackdata = personaldata.feedback_personal;
	var mypersonalContent = "";
	$(feedbackdata)
			.each(
					function(index, Element) {
						if (feedbackdata[index].category === 'inputarea') {
							mypersonalContent = mypersonalContent
									+ "<div><label class='contacts-title'>"
									+ feedbackdata[index].labelcontent
									+ "</label><textarea   rows='6' style='max-width:50em ;max-height:18em;' id='"
									+ feedbackdata[index].id
									+ "'></textarea></div>";
						} else if (feedbackdata[index].category === 'input') {
							mypersonalContent = mypersonalContent
									+ "<div><label class='contacts-title'>"
									+ feedbackdata[index].labelcontent
									+ "</label><input type='"
									+ feedbackdata[index].type + "' size ='"
									+ feedbackdata[index].size + "' /></div>";
						} else if (feedbackdata[index].category === 'select') {
							mypersonalContent = mypersonalContent
									+ "<div><label class='contacts-title'>"
									+ feedbackdata[index].labelcontent
									+ "</label><select id='"
									+ feedbackdata[index].id
									+ "'  tabindex='1'> ";
							var selectsections = feedbackdata[index].sections;
							$(selectsections).each(
									function(indexes, Element) {

										mypersonalContent = mypersonalContent
												+ "<option value='"
												+ selectsections[indexes].value
												+ "'>"
												+ selectsections[indexes].title
												+ "</option> ";

									});

							mypersonalContent = mypersonalContent
									+ "</select></div>";

						}

					});

	$('#personalFeedback').append(mypersonalContent).trigger('create');

}

function applyFancyfield(personaldata) {

	var feedbackdata = personaldata.feedback_content;
	$(feedbackdata).each(function(index, Element) {
		if (feedbackdata[index].category === 'select') {
			var selectsections = feedbackdata[index].sections;
			$(selectsections).each(function(indexes, Element) {
				var data = "#" + selectsections[indexes].title;
				// $("'#" + selectsections[indexes].title+"'").fancyfields();
				$(data).fancyfields();
			});
		}
	});

	$('div.ffRadioWrapper').parent().unwrap();
	$('#feedbacksubmit').fancyfields();
	$('#ss-submit').fancyfields();

}

function fillFeedbackcourse(personaldata) {
	var feedbackdata = personaldata.feedback_content;
	var mypersonalContent = "";
	$(feedbackdata)
			.each(
					function(index, Element) {
						if (feedbackdata[index].category === 'inputarea') {
							mypersonalContent = mypersonalContent
									+ "<div><label class='contacts-title'>"
									+ feedbackdata[index].labelcontent
									+ "</label><textarea   rows='6' style='max-width:50em ;max-height:18em;' id='"
									+ feedbackdata[index].id
									+ "'></textarea></div>";
						} else if (feedbackdata[index].category === 'select') {
							mypersonalContent = mypersonalContent
									+ "<label class='contacts-title'>"
									+ feedbackdata[index].labelcontent
									+ "</label><ul><li>";
							var selectsections = feedbackdata[index].sections;
							$(selectsections)
									.each(
											function(indexes, Element) {
												mypersonalContent = mypersonalContent
														+ "<span><input  type='radio' id='"
														+ selectsections[indexes].title
														+ "' value='"
														+ selectsections[indexes].value
														+ "' name='"
														+ feedbackdata[index].id
														+ "'>"
														+ "<label style='width:10px;'>"
														+ selectsections[indexes].value
														+ "</label></span>";

											});
							mypersonalContent = mypersonalContent
									+ "</li></ul>";
						}

					});
	$('#courseFeedback').append(mypersonalContent).trigger('create');
	$('.ui-radio').children().unwrap();
	$('.ffRadio').children().unwrap();

}

function fillAboutPagewithData(aboutdata) {
	var aboutcontent = aboutdata.about_content;
	var myaboutContent = "";
	$(aboutcontent).each(
			function(index, Element) {
				myaboutContent = myaboutContent
						+ "<p class='info-18 textcolor' id='"
						+ aboutcontent[index].id + "'";
				myaboutContent = myaboutContent
						+ "style='text-align: justify;'></p>";

			});
	$('#about-content').append(myaboutContent);
	$(aboutcontent).each(function(index, Element) {
		$('#' + aboutcontent[index].id).text(aboutcontent[index].content);
	});
}

function fillAndroidOfferings(coursedata) {
	var android_content = coursedata.courses.Android[0];
	$('#android_bootcamp').append(
			drawtitleofWorkShop(android_content.id, android_content.href,
					android_content.course));
	drawWorkshopHeaders(android_content.sections, 'android_section');
	$('#android_workshop_description').text(android_content.descriptions);

	var android_prereq = android_content.prerequest[0];
	$('#android_prereq').append(android_prereq.description);
	var dataContent = "";
	$(android_prereq.musthave).each(function(index, Element) {
		dataContent += "<li>" + android_prereq.musthave[index].item + "</li>";
	});

	$('#android_prereq_list').append(dataContent);

	var androidLearnings = $('#android-learnings');
	dataContent = "";
	$(android_content.learnings).each(
			function(index, Element) {
				dataContent += "<li>" + android_content.learnings[index].title
						+ "</li>";
			});
	androidLearnings.append(dataContent);
	var androidday1 = $('#android-day1');
	dataContent = "";
	$(android_content.agendaday1).each(
			function(index, Element) {
				dataContent += "<li>" + android_content.agendaday1[index].topic
						+ "</li>";
			});
	androidday1.append(dataContent);
	dataContent = "";
	var androidday2 = $('#android-day2');
	$(android_content.agendaday2).each(
			function(index, Element) {
				dataContent += "<li>" + android_content.agendaday2[index].topic
						+ "</li>";
			});
	androidday2.append(dataContent);
}

function fillOOPSOfferings(coursedata) {
	var course_content = coursedata.courses.oopsjava[0];
	$('#oops_bootcamp').append(
			drawtitleofWorkShop(course_content.id, course_content.href,
					course_content.course));
	drawWorkshopHeaders(course_content.sections, 'oops_section');
	$('#oops_workshop_description').text(course_content.descriptions);

	var course_prereq = course_content.prerequest[0];
	$('#oops_prereq').append(course_prereq.description);
	var dataContent = "";
	$(course_prereq.musthave).each(function(index, Element) {
		dataContent += "<li>" + course_prereq.musthave[index].item + "</li>";
	});

	$('#oops_prereq_list').append(dataContent);

	var oopsLearnings = $('#oops-learnings');
	dataContent = "";
	$(course_content.learnings).each(
			function(index, Element) {
				dataContent += "<li>" + course_content.learnings[index].title
						+ "</li>";
			});
	oopsLearnings.append(dataContent);
	var oopsday1 = $('#oops-day1');
	dataContent = "";
	$(course_content.agendaday1).each(
			function(index, Element) {
				dataContent += "<li>" + course_content.agendaday1[index].topic
						+ "</li>";
			});
	oopsday1.append(dataContent);
	dataContent = "";
	var oopsday2 = $('#oops-day2');
	$(course_content.agendaday2).each(
			function(index, Element) {
				dataContent += "<li>" + course_content.agendaday2[index].topic
						+ "</li>";
			});
	oopsday2.append(dataContent);
}

function drawtitleofWorkShop(titleId, location, coursetitle) {
	var workshoptitle = "<div class='center-workshop-android' id='" + titleId
			+ "'> <img src='" + location + "'alt='' /><span>" + coursetitle
			+ "</span>";
	return workshoptitle;
}

function drawWorkshopHeaders(datasections, sectionsids) {
	$(datasections)
			.each(
					function(index, Element) {
						var workshopsections = "<div class='container-title small-container-title'><span style='color: #DC143C;'>"
								+ datasections[index].content + "</span></div>";
						$('#' + sectionsids + index).prepend(workshopsections);

					});

}

function fillcredentials(offeringsdata) {
	$('#credentails_p1').append(offeringsdata.courses.Android[0].descriptions);
	$('#credentails_p2').append(offeringsdata.courses.Android[0].descriptions);
	var mydata = offeringsdata.courses.Android[0].sections;
	var visionmission = "";

	$(mydata)
			.each(
					function(index, Element) {
						visionmission = visionmission
								+ "<div class='center-data'><div class='grids_mynew' style='margin-left:30px;'>";
						visionmission = visionmission
								+ "<span class='logo-color'>"
								+ mydata[index].title
								+ "</span>  <p class='textcolor'><img src="
								+ mydata[index].location
								+ " width='240' height='100'>"
								+ mydata[index].description
								+ "</p></div></div>";
					});
	$('#main-container').append(visionmission);
}

function filldrawTableContents(data) {
	var contact_table_content = data.contact_content;
	var mytemplate = "";
	$(contact_table_content).each(
			function(index, Element) {
				mytemplate = mytemplate
						+ "<tr> <td class='contacts-left-title'>"
						+ contact_table_content[index].title
						+ "</td><td class='nowrap textcolor contact-font'>";
				mytemplate = mytemplate + contact_table_content[index].content
						+ "</td></tr>";
			});
	$('#tablecontent').append(mytemplate);

}

function drawMenuHeaders(data) {
	var menu_header_content = data.menu_content;
	var mymenutemplate = "";
	$(menu_header_content).each(
			function(index, Element) {
				mymenutemplate = mymenutemplate + "<li> <a class='fNiv' id='"
						+ menu_header_content[index].id + "'>"
						+ menu_header_content[index].title + "</a>";
				var sections = menu_header_content[index].sections;
				if (sections) {
					var sectiontemplate = "<ul><li class='arrow'></li>";
					$(sections).each(
							function(index, Element) {
								sectiontemplate = sectiontemplate
										+ "<li><a id='" + sections[index].id
										+ "'>" + sections[index].title
										+ "</a></li>";
							});
					sectiontemplate = sectiontemplate + "</ul></li>";

					mymenutemplate = mymenutemplate + sectiontemplate;

				} else {
					mymenutemplate = mymenutemplate + "</li>";
				}

			});

	$('#jMenu').append(mymenutemplate).trigger('create');

	$(menu_header_content)
			.each(
					function(index, Element) {
						var sections = menu_header_content[index].sections;
						if (menu_header_content[index].navigate) {
							var ids = "#" + menu_header_content[index].id;
							$(ids)
									.click(
											function() {

												$(window)
														.stop(true)
														.scrollTo(
																$(menu_header_content[index].navigate),
																3000,
																{
																	duration : 400,
																	easing : 'swing',
																	durationMode : 'each',
																	offsetTop : 50,
																	offsetLeft : 50
																});
											});
						}
						if (sections) {
							$(sections)
									.each(
											function(indexs, Element) {
												var ids = "#"
														+ sections[indexs].id;
												$(ids)
														.click(
																function() {

																	$(window)
																			.stop(
																					true)
																			.scrollTo(
																					$(sections[indexs].navigate),
																					3000,
																					{
																						duration : 400,
																						easing : 'swing',
																						durationMode : 'each',
																						offsetTop : 50,
																						offsetLeft : 50
																					});
																});

											});
						}

					});
}
function drawsectionHeaders(data) {
	var section_header_content = data.header_content;
	$(section_header_content)
			.each(
					function(index, Element) {
						var myHeaderTemplate = "";
						myHeaderTemplate = myHeaderTemplate
								+ " <div class='row-fluid'> <div class='span12'> <h4 class='pageHeader-85'>"
								+ section_header_content[index].title;
						myHeaderTemplate = myHeaderTemplate
								+ "</h4> <p class='info-18' style='text-align: center;'>"
								+ section_header_content[index].content
								+ "</p> </div> </div>";
						$('#' + section_header_content[index].id).append(
								myHeaderTemplate);

						var subheaderTemplate = " ";
						subheaderTemplate = subheaderTemplate
								+ "<div class='row'><p class='contact-para'><font style='color: #DC143C;'\'>"
								+ section_header_content[index].subheader_content;

						subheaderTemplate = subheaderTemplate
								+ "</font> </p> <p class='separator-type-1'></p> </div> ";
						$('#' + section_header_content[index].subheader_id)
								.append(subheaderTemplate);

					});

}

function drawCredentialsLeftSectionHeaders(data) {
	var leftPanelContent = "<div class='left-cont'><div class='service-in'><img src='img/ccc/staffing-1.jpg' width='280' height='236' class='imagebg'></div><ul class='leftholder marginList'>"
	var leftPanelList = data.left_menu_content;
	$(leftPanelList).each(
			function(index, Element) {
				leftPanelContent = leftPanelContent + "<li><a id='"
						+ leftPanelList[index].id + "'>"
						+ leftPanelList[index].title + "</a></li>";
			});
	leftPanelContent = leftPanelContent + "</ul></div>";
	console.log("Left Panel Conttent :  " + leftPanelContent);
	return leftPanelContent;

}

function drawCredentialsRightSectionHeaders(data) {
	var rightPanelContent = "<div class='right-cont'><div class='contin'><div class='post-cont'>";
	var rightPanelList = data.left_menu_content;
	$(rightPanelList).each(
			function(index, Element) {
				rightPanelContent = rightPanelContent + "<li><a id='"
						+ rightPanelList[index].id + "'>"
						+ rightPanelList[index].title + "</a></li>";
			});
	rightPanelContent = rightPanelContent + "</div></div></div>";
	console.log("Right Panel Conttent :  " + rightPanelContent);
	return rightPanelContent;

}

function drawCredentialContent(data) {

	var leftPanelContent = "<div class='left-sidebar'><div class=' lef-padding'><div class=' data-link'><div class=' content-panel'><div class='left-cont'><div class='service-in'><img src='img/ccc/staffing-1.jpg' width='280' height='236' class='imagebg'></div><div class='clear'></div><ul class='leftholder marginList'>"
	var leftPanelList = data.left_menu_content;
	$(leftPanelList).each(
			function(index, Element) {
				leftPanelContent = leftPanelContent + "<li><a id='"
						+ leftPanelList[index].id + "'>"
						+ leftPanelList[index].title + "</a></li>";
			});
	leftPanelContent = leftPanelContent + "</ul></div></div></div></div></div>";

	console.log("Left content " + leftPanelContent);
	var rightPanelContent = "<div class='right-cont'><div class='contin'><div class='post-cont'>";
	var rightPanelList = data.left_menu_content;
	$(rightPanelList).each(
			function(index, Element) {
				rightPanelContent = rightPanelContent + "<div id='"
						+ rightPanelList[index].id + "'></div>";
			});
	rightPanelContent = rightPanelContent + "<div class='clear'></div> <div class='clear'></div><div class='clear'><div class='clear'></div>";
	console.log("Right Panel Conttent :  " + rightPanelContent);
	var mycredentails = "";
	mycredentails = mycredentails + leftPanelContent + rightPanelContent;
	mycredentails =mycredentails+"<div class='clear'></div>";
	
	

	$('#ccc_credentials').append(mycredentails).trigger('create');

}
function calltoJMenu() {
	$("#jMenu").jMenu({
		openClick : false,
		ulWidth : 'auto',
		effects : {
			effectSpeedOpen : 150,
			effectSpeedClose : 150,
			effectTypeOpen : 'slide',
			effectTypeClose : 'hide',
			effectOpen : 'linear',
			effectClose : 'linear'
		},
		TimeBeforeOpening : 100,
		TimeBeforeClosing : 11,
		animatedText : false,
		paddingLeft : 1
	});
}
